package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_JunMing_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.JunMingRongHe;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class JunMing_Adapter extends BaseAdapter {
    private Context context;
    private ArrayList<JunMingRongHe> list;

    public JunMing_Adapter(Context context, ArrayList<JunMingRongHe> list) {
        super();
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        Holder mHolder;
        if (arg1 == null) {
            mHolder = new Holder();
            arg1 = View.inflate(context, R.layout.skill_lietview_layout, null);
            mHolder.junming_ronghe_title = (TextView) arg1.findViewById(R.id.junming_ronghe_title);
            mHolder.junming_ronghe_parent_name = (TextView) arg1.findViewById(R.id.junming_ronghe_parent_name);
            arg1.setTag(mHolder);
        }
        mHolder = (Holder) arg1.getTag();
        mHolder.junming_ronghe_title.setText(list.get(arg0).getTitle());
        mHolder.junming_ronghe_parent_name.setText("分类专属 :" + "   " + list.get(arg0).getName());
        final int a = arg0;
        arg1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Main_JunMing_DetailsActivity.class);
                intent.putExtra("junming_id", list.get(a).getId());
                intent.putExtra("junming_parent_name", list.get(a).getName());
                context.startActivity(intent);
            }
        });
        return arg1;
    }

    class Holder {
        TextView junming_ronghe_title;
        TextView junming_ronghe_parent_name;
    }
}
